package Test_4_16;

import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;

public class test1 {
   /* public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String a = in.nextLine();
            System.out.println(getString(a));
        }
    }

    public static String getString(String a){
        Stack<Character> stack = new Stack<Character>();
        stack.push(a.charAt(0));
        for(int i=1;i<a.length();i++){
            char ch = a.charAt(i);
            if(!stack.isEmpty()&&stack.peek()!=ch){
                stack.push(ch);
            }else{
                stack.pop();
            }
        }
        String str = "";
        while(!stack.isEmpty()){
            str = stack.pop()+str;
        }
        return str;
    }*/


/*    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int cost = 0;
        // 注意 while 处理多个 case
        double a = in.nextDouble();
        String b = in.next();
        char c = b.charAt(0);
        if(a<=1){
            cost=20;
        }else if(a>1&&a%1!=0){
            cost = 20+(int)(a-1)+1;
        }else if(a>1&&a%1==0){
            cost = 20+(int)(a-1);
        }
        if(c=='y'){
            //表示加急
            cost+=5;
        }
        System.out.println(cost);
    }*/


   /* public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int[] arr1 = new int[a];
        for(int i=0;i<a;i++){
            arr1[i] = in.nextInt();
        }
        if(a==2){
            System.out.println(Math.min(arr1[0],arr1[1]));
        }else{
            int[] cost = new int[a+1];
            for (int i = 2; i <=a ; i++) {
                cost[i] = Math.min(cost[i-1]+arr1[i-1],cost[i-2]+arr1[i-2]);
            }
            System.out.println(cost[a]);
        }
    }*/


    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        String[] str = new String[a];
        for(int i = 0;i<a;i++){
             str[i] = in.nextLine();
        }
        String str1 = in.nextLine();
        String str2 = in.nextLine();
        if (str1.length() == 0 || str2.length() == 0) {
            System.out.println(-1);
        } else {
            int x = -1, y = -1;
            for (int i = 0; i < a; i++) {
                if (str[i].equals(str1)) {
                    x = i;
                }
                if (str[i].equals(str2)) {
                    y = i;
                }
            }
            if (x != -1 && y != -1) {
                System.out.println(Math.abs(x - y));
            } else {
                System.out.println(-1);
            }
        }
        System.out.println();
    }
}
